package cn.shop.dys.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.ValueListBean;


/**
 * Created by sugar0811 on 2016/4/20.
 */
public class FreeFilterView extends GridView {

    private Button textView;

    public FreeFilterView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

    private void init() {

        /**
         * android:layout_margin="8dp"
         android:textSize="24sp"
         android:gravity="center"
         android:background="@drawable/shape_selsect_text_bg"
         android:layout_width="100dp"
         android:layout_height="35dp"
         */
        setNumColumns(3);
        setHorizontalSpacing(5);
        setVerticalSpacing(5);
        setPadding(6, 6, 6, 10);
//        textView = new Button(getContext());
//        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(getContext(),null);
//        layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
//        layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
//        textView.setLayoutParams(layoutParams);
    }

    private List<ValueListBean> items;

    public void setItems(List<ValueListBean> items) {
        if (items == null) return;
        if (items != this.items) {
            this.items = items;
            setAdapter(new myAdapter());
        }
    }


    class myAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return items == null ? 0 : items.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ValueListBean content = items.get(position);
            TextView tv = (TextView) View.inflate(getContext(), R.layout.item_select_text, null);
            tv.setText(content.getName());
            return tv;
        }
    }

}
